﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MglMES
{
    public class MyControlBase : UserControl
    {
        public Timer timer1;
        private IContainer components;

        public MyControlBase()
        {
      
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);
            if (Application.StartupPath.Contains("Debug"))
            {
                if (Parent != null)
                {
                    timer1 = new Timer();
                    timer1.Interval = 500;
                    timer1.Start();
                    timer1.Tick += new EventHandler(Timer_Tick);
                    ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
                    ParentForm.TopLevel = true;
                    ParentForm.AutoSize = true;
                    ParentForm.Text = Name;
                    ParentForm.Width = this.Width;
                    ParentForm.Height = this.Height + 50;
                    this.Dock = DockStyle.Fill;
                }
            }
        }


        protected virtual void Timer_Tick(object sender, EventArgs e) { }


        private void ParentForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ParentForm.Controls.Clear();
            timer1.Stop();
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Interval = 500;
            // 
            // MyControlBase
            // 
            this.Name = "MyControlBase";
            this.Size = new System.Drawing.Size(36, 24);
            this.ResumeLayout(false);

        }
    }
}
